package pprz.light;

import java.awt.BasicStroke;
import java.awt.Component;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Rectangle;
import java.awt.RenderingHints;
import java.awt.Shape;
import java.awt.geom.Ellipse2D;
import java.awt.geom.Rectangle2D;
import java.awt.geom.RoundRectangle2D;

public class LightBorder extends Component {

	static final long serialVersionUID=1;
	protected int thickness;
	protected Shape shape;
	
	public LightBorder(Shape shape, int thickness)
	{
		this.shape=shape;
		this.thickness=thickness;
	}
	
	@Override
	public void paint(Graphics g) {
		super.paint(g);
		Graphics2D g2=(Graphics2D)g;
		g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);		
		g2.setStroke(new BasicStroke(thickness));
		g2.setPaint(this.getForeground());
		g2.draw(shape);
	}
	
	public Shape getShape() {return shape;}

	@Override
	public void setBounds(int x, int y, int width, int height) {
		Class o=shape.getClass();
		if (o.equals(Rectangle2D.Float.class) || o.equals(Rectangle2D.Double.class))
			shape=new Rectangle2D.Float(x,y,width-thickness,height-thickness);
		else if (o.equals(Rectangle.class))
			shape=new Rectangle2D.Float(x+thickness/2,y+thickness/2,width-thickness,height-thickness);
		else if (o.equals(RoundRectangle2D.Float.class) || o.equals(RoundRectangle2D.Double.class))
			shape=new RoundRectangle2D.Float(x+thickness/2,y+thickness/2,width-thickness,height-thickness,width/4,height/4);
		else if (o.equals(Ellipse2D.Float.class) || o.equals(Ellipse2D.Double.class))
			shape=new Ellipse2D.Float(x+thickness/2,y+thickness/2,width-thickness,height-thickness);
		
		super.setBounds(x, y, width, height);
	}
	
	
	
}
